home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX8_4.C < prev    next >
C/C++ Source or Header  |  1992-09-28  |  2KB  |  40 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/String.h>            // COOL String class
  14. #include <cool/Set.h>                // COOL Set class
  15.  
  16. #include <cool/Set.C>
  17.  
  18. Boolean my_compare (const CoolString& s1, const CoolString& s2) {
  19.   return ((strcmp (s1, s2) == 0) ? TRUE : FALSE);
  20. }
  21.  
  22. static CoolString color_table[] = { "RED", "YELLOW", "PINK", "GREEN",
  23.                     "ORANGE", "PURPLE", "BLUE" };
  24.  
  25. int main (void) {
  26.   CoolSet<CoolString> a(5), b(5);        // Declare two CoolSet objects
  27.   a.set_compare (&my_compare);            // Establish compare function
  28.   for (int i = 0; i < 5; i++) {            // For each color defined
  29.     a.put (color_table[i]);            // Add object to first CoolSet
  30.     b.put (color_table[6-i]);            // Add end object to second CoolSet
  31.   }
  32.   cout << "Set A contains: " << a;         // Elements of CoolSet 1
  33.   cout << "Set B contains: " << b;         // Elements of CoolSet 2
  34.   cout << "A | B: " << (a | b);            // Display union
  35.   cout << "A & B: " << (a & b);            // Display intersection
  36.   cout << "A ^ B: " << (a ^ b);            // Display XOR
  37.   cout << "A - B: " << (a - b);            // Display difference
  38.   return (0);                    // Exit with OK status
  39. }
  40.